package com.easy.dfc.web;

import com.easy.common.bean.Result;
import com.easy.common.constant.EnumConfig;
import com.easy.core.web.BaseController;
import com.easy.dfc.entity.ParaFactoryProducts;
import com.easy.dfc.service.FactoryIndexService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Controller
@RequestMapping(value = "${apiPath}/FactoryIndex/")
public class FactoryIndexController extends BaseController {

    @Resource
    private FactoryIndexService factoryIndexService;

    /**
     * 厂家版首页
     * @param model
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "HomePage")
    public Result HomePage(Model model) {
        try {
            return factoryIndexService.HomePage();
        } catch (Exception e) {
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.DB_ERROR);
            return rt;
        }
    }

    /**
     * 获取厂品类型
     * @param model
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "getCateories", method = RequestMethod.POST)
    public Result getCateories(@RequestBody ParaFactoryProducts para,Model model) {
        try {
            return factoryIndexService.getCateories(para.getTypeId());
        } catch (Exception e) {
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.DB_ERROR);
            return rt;
        }
    }

    /**
     * 获取厂品列表
     * @param model
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "getProducts", method = RequestMethod.POST)
    public Result getProducts(@RequestBody ParaFactoryProducts para, Model model) {
        try {
            return factoryIndexService.getProducts(para);
        } catch (Exception e) {
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.DB_ERROR);
            return rt;
        }
    }
}
